/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.zcm.modules.bzy.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.zcm.common.config.Global;
import com.zcm.common.persistence.Page;
import com.zcm.common.web.BaseController;
import com.zcm.common.utils.StringUtils;
import com.zcm.modules.bzy.entity.BzyConfig;
import com.zcm.modules.bzy.service.BzyConfigService;

/**
 * 八爪鱼配置Controller
 * @author www
 * @version 2018-10-23
 */
@Controller
@RequestMapping(value = "${adminPath}/bzy/bzyConfig")
public class BzyConfigController extends BaseController {

	@Autowired
	private BzyConfigService bzyConfigService;
	
	@ModelAttribute
	public BzyConfig get(@RequestParam(required=false) String id) {
		BzyConfig entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = bzyConfigService.get(id);
		}
		if (entity == null){
			entity = new BzyConfig();
		}
		return entity;
	}
	
	@RequiresPermissions("bzy:bzyConfig:view")
	@RequestMapping(value = {"list", ""})
	public String list(BzyConfig bzyConfig, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<BzyConfig> page = bzyConfigService.findPage(new Page<BzyConfig>(request, response), bzyConfig); 
		model.addAttribute("page", page);
		return "modules/bzy/bzyConfigList";
	}

	@RequiresPermissions("bzy:bzyConfig:view")
	@RequestMapping(value = "form")
	public String form(BzyConfig bzyConfig, Model model) {
		model.addAttribute("bzyConfig", bzyConfig);
		return "modules/bzy/bzyConfigForm";
	}

	@RequiresPermissions("bzy:bzyConfig:edit")
	@RequestMapping(value = "save")
	public String save(BzyConfig bzyConfig, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, bzyConfig)){
			return form(bzyConfig, model);
		}
		bzyConfigService.save(bzyConfig);
		addMessage(redirectAttributes, "保存八爪鱼任务配置成功");
		return "redirect:"+Global.getAdminPath()+"/bzy/bzyConfig/?repage";
	}
	
	@RequiresPermissions("bzy:bzyConfig:edit")
	@RequestMapping(value = "delete")
	public String delete(BzyConfig bzyConfig, RedirectAttributes redirectAttributes) {
		bzyConfigService.delete(bzyConfig);
		addMessage(redirectAttributes, "删除八爪鱼任务配置成功");
		return "redirect:"+Global.getAdminPath()+"/bzy/bzyConfig/?repage";
	}

}